package com.onpositive.knowledge.model.value.audits;

public class Range {

	public final Comparable<?> from;
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((from == null) ? 0 : from.hashCode());
		result = prime * result + ((to == null) ? 0 : to.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Range other = (Range) obj;
		if (from == null) {
			if (other.from != null)
				return false;
		} else if (!from.equals(other.from))
			return false;
		if (to == null) {
			if (other.to != null)
				return false;
		} else if (!to.equals(other.to))
			return false;
		return true;
	}

	public final Comparable<?> to;

	public Range(Comparable<?> from, Comparable<?> to) {
		super();
		this.from = from;
		this.to = to;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public boolean includes(Range r1) {
		try {
			if (from != null) {
				int c0 = ((Comparable) from).compareTo((Comparable) r1.from);
				if (c0 < 0) {
					return false;
				}
			}
			if (to != null) {
				int c0 = ((Comparable) to).compareTo((Comparable) r1.to);
				if (c0 > 0) {
					return false;
				}
			}
		} catch (Exception e) {
			
		}
		return false;
	}
}
